package com.hsy.order.base.ui.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import com.flux.ui.activity.FBaseActivity
import com.flux.utils.GlideUtil
import com.hsy.order.R
import java.lang.ref.WeakReference

/**
 * Created on 2018/1/30.
 *
 * @author Yang
 */
class ImageGridAdapter(activity: FBaseActivity, val data: MutableList<String>)  : BaseAdapter() {

    private val mActivity: WeakReference<FBaseActivity> = WeakReference(activity)

    override fun getCount(): Int {
        return data.size
    }

    override fun getItem(position: Int): Any {
        return data[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, view: View?, parent: ViewGroup): View {
        var convertView = view
        val holder: ViewHolder
        if (null == convertView) {
            convertView = mActivity.get()!!.layoutInflater.inflate(R.layout.item_circle_grid, parent, false)
            holder = ViewHolder()
            convertView!!.tag = holder
            holder.img = convertView.findViewById(R.id.item_circle_grid)
        } else {
            holder = convertView.tag as ViewHolder
        }
        GlideUtil.load(mActivity.get()!!, data[position], holder.img)
        return convertView
    }

    private inner class ViewHolder {
        lateinit var img: ImageView
    }
}